#!/bin/bash
# Author : Syuan-Rong Chen
# E-mail : calvin.atx@gmail.com
# Blog：   http://calvinit.blogspot.com
# Date : 20100812
#
# <description>
# Copyright (C) <year>  <name> <email>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
dfpath=$HOME/calvin
appath=$HOME/calvin/cvirt
netpath=$HOME/calvin/cvirt/net
drvm=$HOME/calvin/cvirt/virt_net.txt
vmnum=$(wc $HOME/calvin/d-cvirt/virt_net.txt|fmt -u|cut -d' ' -f3)
[ ! -e $netpath ]&& mkdir $netpath

clear

function ck_vm {
	if [ ! -e $drvm  ]; then
		[ ! -e $dfpath ]&& mkdir $dfpath
		[ ! -e $appath ]&& mkdir $appath
		touch $drvm 
		echo $HOME/calvin/cvirt/net/:net1 >> $drvm 
		nano $drvm 
	else
		nano $drvm 
	fi
}

function outputMenu {

echo -e '\E[1;33m'"歡迎使用Calvin_Virt Manager"; tput sgr0
echo ""
echo -e '\E[1;32m'"本程式主要功能為虛擬網路的各項操作"; tput sgr0
echo -e '\E[1;36m'"請先編輯virt_net才能確保程式功能完整"
echo "virt_net內容的格式請參考以下(路徑為絕對路徑最後面需加/)
/存放路徑/:網路名稱"; tput sgr0
echo -e '\E[1;31m'"[e] 編輯virt_net設定檔"; tput sgr0
echo ""
echo -e '\E[1;32m'"虛擬網路 啟用/停用/重新啟用"; tput sgr0
echo "[1] 啟用"
echo "[2] 停用"
echo "[3] 重新啟用"
echo ""
echo -e '\E[1;32m'"虛擬網路 備份/還原/刪除"; tput sgr0
echo "[4] 備份成XML檔(XML檔案不存在時會自動備份)"
echo "[5] 用XML檔定義虛擬網路至清單"
echo "[6] 從清單中刪除虛擬網路"
echo ""
echo "[0] 回上一層"

echo ""
echo -ne "請選擇: "
read USERCHOICE
clear

case $USERCHOICE in
        "e") ck_vm ;;
        "1") . /usr/cbin/d-cvirt/netctl_st.sh ;;
        "2") . /usr/cbin/d-cvirt/netctl_sp.sh ;;
	"3") . /usr/cbin/d-cvirt/netctl_rb.sh ;;
        "4") . /usr/cbin/d-cvirt/netcbk_bk.sh ;;
        "5") . /usr/cbin/d-cvirt/netcbk_rs.sh ;;
	"6") . /usr/cbin/d-cvirt/netcbk_de.sh ;;
	"0") . /usr/cbin/d-cvirt/main.sh ;;
        *) echo "請輸入正確的選擇";;
esac
}

. /usr/cbin/c/domenu.sh

